package com.work;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class WorkCustomers {
    //work之平均分配
    /*@RabbitListener(queuesToDeclare = @Queue("work"))
    public void customer1(String message){
        System.out.println("消费者1："+message);
    }
    @RabbitListener(queuesToDeclare = @Queue("work"))
    public void customer2(String message){
        System.out.println("消费者2："+message);
    }*/
    //work之能者多劳-只需添加配置文件即可
    @RabbitListener(queuesToDeclare = @Queue("work"))
    public void customer1(String message) throws IOException {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("消费者1:"+message);
    }
    @RabbitListener(queuesToDeclare = @Queue("work"))
    public void customer2(String message, Channel channel) throws IOException {
        System.out.println("消费者2:"+message);
    }
}
